package saucaca.Adapter;

import java.util.ArrayList;

import saucaca.Object.RingtoneObject;
import saucaca.fragment.RingToneListSong;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.kenhnhacvn.MainActivity;
import com.lemon.kenhnhacvn.R;

public class RingtoneAdapter extends BaseAdapter {
	Context context;
	private LayoutInflater inflater;
	private ArrayList<RingtoneObject> listSongs = new ArrayList<RingtoneObject>();

	public RingtoneAdapter(Context context, ArrayList<RingtoneObject> _list) {
		listSongs = _list;
		this.context = context;
		this.inflater = LayoutInflater.from(context);
	}

	public void setList(ArrayList<RingtoneObject> _list) {
		listSongs = _list;
		notifyDataSetChanged();
	}

	public ArrayList<RingtoneObject> getList() {
		return listSongs;
	}

	class ViewHolder {
		LinearLayout layout;
		TextView textViewNumber;
		TextView textViewTitle;
		TextView textViewArtist;
		ImageView imgeView, img_album;
		ImageButton imgMenu;
		View layout_index;
	}

	@Override
	public int getCount() {
		return listSongs.size();
	}

	@Override
	public Object getItem(int position) {
		return listSongs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_song_local, null);
			holder.layout = (LinearLayout) convertView.findViewById(R.id.localmusic_linearSong);
			holder.textViewTitle = (TextView) convertView.findViewById(R.id.song_title);
			holder.textViewArtist = (TextView) convertView.findViewById(R.id.song_artist);
			holder.imgMenu = (ImageButton) convertView.findViewById(R.id.popup_menu);
			holder.layout_index = convertView.findViewById(R.id.layout_index);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.layout_index.setVisibility(View.GONE);
		holder.imgMenu.setVisibility(View.GONE);

		holder.layout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				((MainActivity) context).switchContent(RingToneListSong.class.getName(), listSongs.get(position));
			}
		});

		holder.textViewTitle.setText(listSongs.get(position).getTXNAME());
		holder.textViewArtist.setText(listSongs.get(position).getNAME_SINGERS());

		return convertView;
	}

}
